home *** CD-ROM | disk | FTP | other *** search
- #pragma implementation
- #include <stdlib.h>
- #include <string.h>
- #include <stdio.h>
- #include "../misc/misc.h"
- #include "dialog.h"
- #include "fcombo.h"
-
- PUBLIC ELM_STR::ELM_STR(const char *_value, const char *_verbose)
- {
- value = strdup(_value);
- verbose = strdup(_verbose);
- }
-
- PUBLIC ELM_STR::~ELM_STR()
- {
- free (value);
- free (verbose);
- }
-
- PUBLIC ELM_STR *LIST_STR::getitem(int no)
- {
- return (ELM_STR*)ARRAY::getitem(no);
- }
- /*
- The FIELD_COMBO class is a string editor with an assist
- hot key. When triggered a list of string is displayed
- and the user is allowed to pick a value from there.
- The value (if selected) will replace the input buffer.
- */
- PUBLIC FIELD_COMBO::FIELD_COMBO(
- const char *_prompt,
- SSTRING &_str)
- : FIELD_STRING_HELP (_prompt,_str)
- {
- opts = new LIST_STR;
- }
-
- PUBLIC FIELD_COMBO::~FIELD_COMBO()
- {
- delete opts;
- }
-
- /*
- Add one string option to the combo box pick list
- */
- PUBLIC void FIELD_COMBO::addopt(const char *str)
- {
- opts->add (new ELM_STR(" ",str));
- }
- /*
- Add one string option to the combo box pick list.
- This time there is two string. The strings will be show in
- the pick list like this
-
- value verbose
- */
- PUBLIC void FIELD_COMBO::addopt(const char *value, const char *verbose)
- {
- opts->add (new ELM_STR(value,verbose));
- }
- PROTECTED void FIELD_COMBO::assist(WINDOW *dialog)
- {
- int nbopt = opts->getnb();
- char **tbopt = (char**)malloc_err(nbopt*2*sizeof(char*));
- for (int i=0,ii=0; i<nbopt; i++){
- ELM_STR *elm = opts->getitem(i);
- tbopt[ii++] = elm->value;
- tbopt[ii++] = elm->verbose;
- }
- int sel = 0;
- MENU_STATUS ret = dialog_menu ("Help list"
- ,"Pick one value"
- ,NULL
- ,0
- ,nbopt,tbopt,sel);
- free (tbopt);
- touchwin(stdscr);
- touchwin(dialog);
- if (ret == MENU_OK){
- ELM_STR *elm = opts->getitem(sel);
- if (strcmp(elm->value," ")==0){
- strcpy (buf,elm->verbose);
- }else{
- strcpy (buf,elm->value);
- }
- draw(dialog);
- }
- }
-
- /*
- Add a combo field to the dialog.
- The object will be destroyed by the dialog itself.
- The object is returned so the caller may add options in the
- pick list.
- */
- PUBLIC FIELD_COMBO *DIALOG::newf_combo(
- const char *prompt,
- SSTRING &str)
- {
- FIELD_COMBO *s = new FIELD_COMBO(prompt,str);
- add (s);
- return s;
- }
-
-